local AddOnName, Env = ... local ADDON = Env[1]
-- ~~| Libraries |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local DiesalTools 	= LibStub("DiesalTools-1.0")
local DiesalStyle 	= LibStub("DiesalStyle-1.0") 
local DiesalGUI 		= LibStub("DiesalGUI-1.0")
-- ~~| Lua Upvalues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local print, type, select, tostring, tonumber		= print, type, select, tostring, tonumber
local sub, format, match, lower							= string.sub, string.format, string.match, string.lower
local tsort														= table.sort
local abs														= math.abs
-- ~~| WoW Upvalues |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-- ~~| Developer |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-- ~~| Developer StyleSheets |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local windowStyleSheet = {
	['frame-background'] = {				
		type			= 'texture',
		layer			= 'BACKGROUND',
		color			= '000000',		
		alpha			= .75,			
	},
	['frame-shadow'] = {			
		type			= 'shadow',
		alpha			= 0,		
	},	
	['frame-outline'] = {				
		type			= 'outline',
		layer			= 'BORDER',
		color			= '000000',
		offset		= 0,	
	},	
	['header-background'] = {			
		type			= 'texture',
		layer			= 'BACKGROUND',
		gradient		= 'VERTICAL',						
		color			= '272727',
		colorEnd		= '232323',
		offset 		= {0,0,0,-1},		
	},	
	['header-outline'] = {			
		type			= 'outline',
		layer			= 'BORDER',
		gradient		= 'VERTICAL',		
		color			= 'FFFFFF',		
		alpha			= .05,
		alphaEnd		= .02,
		offset		= {0,0,0,-1},			
	},	
	['header-stroke'] = {			
		type			= 'outline',
		layer			= 'BORDER',
		gradient		= 'VERTICAL',		
		color			= '000000',		
		offset		= {1,1,1,0},			
	},		
}

local logButtonStyle = {
	type			= 'texture',
	texFile		= 'DiesalGUIcons',
	texCoord		= {14,5,16,256,128},
	alpha 		= .7,	
	offset		= {-2,nil,-2,nil},
	width			= 16,
	height		= 16,			
}
local logButtonNormal = {
	type			= 'texture',
	texColor		= 'ffffff',	
	alpha 		= .7,			
}
local logButtonOver = {
	type			= 'texture',	
	alpha 		= 1,		
} 
local logButtonDisabled = {
	type			= 'texture',	
	alpha 		= .3,
}
local clearButtonStyle = {
	type			= 'texture',
	texFile		='DiesalGUIcons',
	texCoord		= {13,5,16,256,128},
	alpha 		= .7,	
	offset		= {-2,nil,-2,nil},
	width			= 16,
	height		= 16,			
}
local clearButtonNormal = {
	type			= 'texture',	
	alpha 		= .7,			
}
local clearButtonOver = {
	type			= 'texture',	
	alpha 		= 1,		
} 
local clearButtonDisabled = {
	type			= 'texture',	
	alpha 		= .3,
}
local reloadButtonStyle = {			
	type			= 'texture',
	texFile		='DiesalGUIcons',
	texCoord		= {3,5,16,256,128},
	alpha 		= .7,	
	offset		= {-2,nil,-2,nil},
	width			= 16,
	height		= 16,			
}
local reloadButtonNormal = {
	type			= 'texture',	
	alpha 		= .7,			
}
local reloadButtonOver = {
	type			= 'texture',	
	alpha 		= 1,		
} 
local reloadButtonDisabled = {
	type			= 'texture',	
	alpha 		= .3,
}
local lineButtonStyle = {
	type			= 'texture',
	texFile		='DiesalGUIcons',
	texCoord		= {15,5,16,256,128},
	alpha 		= .7,	
	offset		= {-2,nil,-2,nil},
	width			= 16,
	height		= 16,			
}
local lineButtonNormal = {
	type			= 'texture',	
	alpha 		= .7,			
}
local lineButtonOver = {
	type			= 'texture',	
	alpha 		= 1,		
} 
local lineButtonDisabled = {
	type			= 'texture',	
	alpha 		= .3,
}
-- ~~| Developer Locals |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

-- ~~| Developer Methods |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
local methods = {	
	['OnAcquire'] = function(self)				
		self.settings 	= DiesalTools:TableCopy( self.defaults )		
					
		self:ApplySettings()					
	end,
	['OnRelease'] = function(self)				
		
	end,		
	['SetSettings'] = function(self,settings,apply)
		for key,value in pairs(settings) do
			self.settings[key] = value
		end
		if apply then self:ApplySettings()	end
	end,
	['ApplySettings'] = function(self)
		local settings = self.settings
		local database = ADDON.db.profile.developer
		local window 	= self.window	
		
		window:SetSettings({
			width				= database.width,
			height			= database.height,			
		})	
		window:UpdatePosition()
		
		self:UpdateButtons()
	end,
	['UpdateButtons'] = function(self)
		local settings = self.settings
		local database = ADDON.db.profile.developer
		
		-- logButton
		if database.logging then 
			logButtonNormal = {
				type			= 'texture',				
				alpha 		= .7,			
			}
		else
			logButtonNormal = {
				type			= 'texture',				
				alpha 		= .3,			
			}			
		end
		
		self.logButton:SetStyle('frame',logButtonNormal)		
	end,		
	['SetText'] = function(self,text)
		self.scrollingEditBox:SetText(text)	
	end,									
}
-- ~~| Developer Constructor |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function ADDON:constructDeveloper()	
	local self = {}	
	-- ~~ Default Settings ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	self.defaults = {		
			
	}	
	-- ~~ Construct ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	local window = DiesalGUI:Create('Window')	
	window:ReleaseTextures()
	window:AddStyleSheet(windowStyleSheet)	
	window:SetSettings({
		left				= 1,
		top				= 1079,
		titleBarHeight	= 3,
		header			= true,		
		headerHeight	= 21,
		sizerR			= false,
		sizerB			= false,		
		sizerBRHeight	= 32,
		sizerBRWidth	= 32,				
	},true)	
	window.sizerBR:SetPoint("BOTTOMRIGHT",window.frame,"BOTTOMRIGHT",-8,0)
	window.sizerBR:SetFrameLevel(100)			
	window:SetEventListener('OnSizeChanged', function(this,event,width,height) 
		local database 	= ADDON.db.profile.developer
		
		database.width 	= width
		database.height 	= height
	end)		
	window.closeButton:Hide()		
	
	local logButton = DiesalGUI:Create('Button')
	logButton:SetParent(window.header)
	logButton:SetPoint('TOPLEFT',0,0)	
	logButton:SetSettings({		
		width			= 20,		
		height		= 20,
	},true)
	logButton:SetStyle('frame',logButtonStyle)	
	logButton:SetEventListener('OnEnter', 	function() 	logButton:SetStyle('frame',logButtonOver) 		end)		
	logButton:SetEventListener('OnLeave', 	function() 	logButton:SetStyle('frame',logButtonNormal)		end)		
	logButton:SetEventListener('OnDisable',function() 	logButton:SetStyle('frame',logButtonDisabled)	end)		
	logButton:SetEventListener('OnEnable', function() 	logButton:SetStyle('frame',logButtonNormal)		end)
	logButton:SetEventListener('OnClick', 	function()
		local database 	= ADDON.db.profile.developer		 
		database.logging 	= not database.logging
		self:UpdateButtons()		
	end)	
	window:AddChild(logButton)
	
	local clearButton = DiesalGUI:Create('Button')
	clearButton:SetParent(window.header)
	clearButton:SetPoint('TOPLEFT',20,0)	
	clearButton:SetSettings({		
		width			= 20,		
		height		= 20,
	},true)
	clearButton:SetStyle('frame',clearButtonStyle)	
	clearButton:SetEventListener('OnEnter', 	function() clearButton:SetStyle('frame',clearButtonOver) 		end)		
	clearButton:SetEventListener('OnLeave', 	function() clearButton:SetStyle('frame',clearButtonNormal)		end)		
	clearButton:SetEventListener('OnDisable', function() clearButton:SetStyle('frame',clearButtonDisabled)	end)		
	clearButton:SetEventListener('OnEnable', 	function() clearButton:SetStyle('frame',clearButtonNormal)		end)	
	clearButton:SetEventListener('OnClick', 	function() 
		ADDON.Log:Clear()
	end)	
	window:AddChild(clearButton)
	
	local reloadButton = DiesalGUI:Create('Button')
	reloadButton:SetParent(window.header)
	reloadButton:SetPoint('TOPLEFT',40,0)	
	reloadButton:SetSettings({		
		width				= 20,		
		height			= 20,		
	},true)
	reloadButton:SetStyle('frame',reloadButtonStyle)	
	reloadButton:SetEventListener('OnEnter', 	function() reloadButton:SetStyle('frame',reloadButtonOver) 		end)		
	reloadButton:SetEventListener('OnLeave', 	function() reloadButton:SetStyle('frame',reloadButtonNormal)	end)		
	reloadButton:SetEventListener('OnDisable',function() reloadButton:SetStyle('frame',reloadButtonDisabled)	end)		
	reloadButton:SetEventListener('OnEnable', function() reloadButton:SetStyle('frame',reloadButtonNormal)	end)
	reloadButton:SetEventListener('OnClick', 	function() ReloadUI() end)	
	window:AddChild(reloadButton)
	
	local lineButton = DiesalGUI:Create('Button')
	lineButton:SetParent(window.header)
	lineButton:SetPoint('TOPLEFT',60,0)	
	lineButton:SetSettings({		
		width			= 20,		
		height		= 20,
	},true)
	lineButton:SetStyle('frame',lineButtonStyle)	
	lineButton:SetEventListener('OnEnter', 	function() lineButton:SetStyle('frame',lineButtonOver) 		end)		
	lineButton:SetEventListener('OnLeave', 	function() lineButton:SetStyle('frame',lineButtonNormal)		end)		
	lineButton:SetEventListener('OnDisable', 	function() lineButton:SetStyle('frame',lineButtonDisabled)	end)		
	lineButton:SetEventListener('OnEnable', 	function() lineButton:SetStyle('frame',lineButtonNormal)		end)
	lineButton:SetEventListener('OnClick', 	function() 
		ADDON.Log:AddMessage('----------------------------------------------------------------------------------------------------')		
	end)
	window:AddChild(lineButton)	
	
	local Button = DiesalGUI:Create('Button')
	Button:SetParent(window.header)
	Button:SetPoint('TOPLEFT',80,0)	
	Button:SetSettings({		
		width			= 20,		
		height		= 20,
	},true)
	Button:SetStyle('frame',lineButtonStyle)	
	Button:SetEventListener('OnEnter', 	function() lineButton:SetStyle('frame',lineButtonOver) 		end)		
	Button:SetEventListener('OnLeave', 	function() lineButton:SetStyle('frame',lineButtonNormal)		end)		
	Button:SetEventListener('OnDisable', 	function() lineButton:SetStyle('frame',lineButtonDisabled)	end)		
	Button:SetEventListener('OnEnable', 	function() lineButton:SetStyle('frame',lineButtonNormal)		end)
	Button:SetEventListener('OnClick', 	function()
		-- PQI_CastSpell(49184) 
		 securecall(PQI_CastSpell,49184)
		ADDON.Log:AddMessage('cast')
	end)
	window:AddChild(Button)	
	
	local depthSpinner = DiesalGUI:Create('Spinner')
	depthSpinner:SetParent(window.header)
	depthSpinner:SetPoint('TOPRIGHT',-2,-2)	
	depthSpinner:SetSettings({
		step	= 5,
		min	= 1,		
		max 	= 200,		
	})	
	depthSpinner:SetNumber(ADDON.db.profile.developer.sessionHistory)
	depthSpinner:SetEventListener('OnValueChanged', function(this,event,userInput,number)
		
		ADDON.db.profile.developer.sessionHistory = number
		ADDON.Log:SetMax(number)
	end)
	window:AddChild(depthSpinner)	
	
	local scrollingEditBox = DiesalGUI:Create('ScrollingEditBox')
	scrollingEditBox:SetParentObject(window)
	scrollingEditBox:SetSettings({		
		contentPadTop		= 2,
		contentPadBottom	= 3,			
	},true)
	scrollingEditBox:SetPoint('TOPLEFT',-1,-1)
	scrollingEditBox:SetPoint('BOTTOMRIGHT',1,-1)
	window:AddChild(scrollingEditBox)
	
	-- ~~ Frames ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	self.window 					= window	
	
	self.logButton 				= logButton
	self.clearButton 				= clearButton
	self.reloadButton 			= reloadButton
	self.lineButton 				= lineButton
	
	self.scrollingEditBox 		= scrollingEditBox
	-- ~~ Methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	for method, func in pairs(methods) do
		self[method] = func
	end	
	-- ~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~			
	return self
end